﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace NFinal
{
    [AttributeUsage(AttributeTargets.Method,Inherited =true)]
    public class AcceptVerbsAttribute : System.Attribute
    {
        public Http.MethodType MethodType {get;set;}

        public AcceptVerbsAttribute(Http.MethodType methodType)
        {
            this.MethodType = methodType;
        }
        public string[] Method
        {
            get
            {
                IList<string> method = new List<string>();
                if ((this.MethodType & Http.MethodType.AJAX) != Http.MethodType.NONE)
                {
                    method.Add("AJAX");
                }
                else if ((this.MethodType & Http.MethodType.DELETE) != Http.MethodType.NONE)
                {
                    method.Add("DELETE");
                }
                else if ((this.MethodType & Http.MethodType.GET) != Http.MethodType.NONE)
                {
                    method.Add("GET");
                }
                else if ((this.MethodType & Http.MethodType.POST) != Http.MethodType.NONE)
                {
                    method.Add("POST");
                }
                else if ((this.MethodType & Http.MethodType.PUT) != Http.MethodType.NONE)
                {
                    method.Add("PUT");
                }
                if (method.Count > 0)
                {
                    return method.ToArray();
                }
                return null;
            }
        }
    }
}
